#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
/*
    出书最多最多问题
    注意find的函数重载问题
*/
using namespace std;
struct books
{
    string author;
    int amount = 1;
    vector<int> book_id;
    // 函数重载，用于find的寻找
    bool operator==(const string &s) // 判断函数的重载，可以写在里面，也可以写在外面，但注意，如有是引用，就必须加const，防止对外部变量的修改。如果不是引用就可以不加
    {
        return this->author == s;
    }
};
bool compare(books book1, books book2)
{
    return book1.amount > book2.amount;
}
int main()
{
    int m;
    cin >> m;
    int book_id;
    vector<books> res;
    books temp;
    string s;
    string single;
    for (size_t i = 0; i < m; i++)
    {
        cin >> book_id;
        cin >> s;
        for (size_t k = 0; k < s.size(); k++)
        {
            single = s[k]; // 注意，s[k]是char类型的，这里通过赋值给string类型能自动完成类型的转换
            auto idex = find(res.begin(), res.end(), single);
            if (idex != res.end())
            {
                // 如果找到了，将书籍导入，并数量加一
                idex->book_id.push_back(book_id);
                idex->amount += 1;
            }
            else
            { // 没找到则全部统一导入
                temp.author = s[k];
                temp.book_id.push_back(book_id);
                res.push_back(temp);
                temp.book_id.clear(); // 这里记得要清空
            }
        }
    }
    sort(res.begin(), res.end(), compare);
    for (auto i = res.begin(); i != res.end(); i++)
    {
        cout << "author: " << i->author << endl;
        cout << "amount: " << i->amount << endl;
    }
    auto be = res.begin();
    cout << be->author << endl;
    cout << be->amount << endl;
    for (size_t i = 0; i < be->book_id.size(); i++)
    {
        cout << be->book_id[i] << endl;
    }
}